<template>
  <a-table
    ref="table"
    size="middle"
    bordered
    rowKey="id"
    :columns="detailColumns"
    :dataSource="dataSource"
    :pagination="ipagination"
    :loading="loading"
    @change="handleTableChange"
  >
  <span slot="bizStatus" slot-scope="text">
      <a-tag color="blue" v-if="text == 0">未使用</a-tag>
      <a-tag color="orange" v-if="text == 1">已使用</a-tag>
  </span>
  </a-table>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'

export default {
  name: 'ReportBalanceList',
  mixins: [JeecgListMixin],
  components: {},
  //接受父组件向子组件传递的数据
  props: ['params'],
  data() {
    return {
      description: '积分变动详情',
      disableMixinCreated: true,
      // 表头
      detailColumns: [
        {
          title: '优惠券名称',
          dataIndex: 'couponNm',
          align: 'center',
        },
        {
          title: '类型',
          dataIndex: 'couponType',
          align: 'center',
          customRender: (text, record) => {
            return text == 'zk' ? '折扣券' : '满减券'
          },
        },
        {
          title: '优惠内容',
          dataIndex: 'couponType',
          align: 'center',
          customRender: (text, record) => {
            if (text == 'zk') {
              return record.ruleVal + '折' + ' (' + '满' + record.lessMoney + '元' + '可用)'
            } else {
              return '减' + record.ruleVal + '元' + ' (' + '满' + record.lessMoney + '元' + '可用)'
            }
          },
        },
        {
          title: '有效期',
          dataIndex: 'validTime',
          align: 'center',
          customRender: (text, record) => {
            return record.validTime + '至' + record.endTime
          },
        },
        {
          title: '领取时间',
          dataIndex: 'getTime',
          align: 'center',
        },
        {
          title: '状态',
          dataIndex: 'bizStatus',
          align: 'center',
          scopedSlots: { customRender: 'bizStatus' }
        },
      ],
      url: {
        list: '/report/member/couponList',
      },
    }
  },
  created() {
    console.log('created')
    this.loadData()
  },
  watch: {
    params: {
        deep: true, // deep 为true  意味着开启了深度监听 a对象里面任何数据变化都会触发handler函数
        handler(){
          console.log('watch params')
          this.loadData()
        }
    }
  },
  methods: {
    loadData(arg) {
      if (arg === 1) {
        this.ipagination.current = 1
      }
      console.log('===params===', this.params)

      //主子表分开维护，生成的代码子表的分页改为真实的分页
      let query = Object.assign(this.params, {
        pageNo: this.ipagination.current,
        pageSize: this.ipagination.pageSize,
      })
      getAction(this.url.list, query).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          console.log(this.dataSource);
          this.ipagination.total = res.result.total
        } else {
          this.dataSource = null
        }
      })
      //主子表分开维护，生成的代码子表的分页改为真实的分页
    },
  },
}
</script>
<style scoped>
</style>